keep gdb route point names and waypoint names aligned. (#1075)
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Fri, 21 Apr 2023 15:51:54 +0000 (09:51 -0600)
committerGitHub <noreply@github.com>
Fri, 21 Apr 2023 15:51:54 +0000 (09:51 -0600)
This used to work in 1.4.4, but stopped working with the conversion
to QString (NEW_STRINGS).

Add a test case to verify the names match.

gdb.cc
reference/route/gdbroutenametest.csv [new file with mode: 0644]
reference/route/gdbroutenametest~csv.csv [new file with mode: 0644]
testo.d/gdb.test

diff --git a/gdb.cc b/gdb.cc
index 7ba6bd6ca0fc0625dd8848e8a87fbadc07f6fa2d..23c77a02e5d09a922e8fd7d65565c0244fe21ceb 100644 (file)
--- a/gdb.cc
+++ b/gdb.cc
@@ -88,12 +88,9 @@ GdbFormat::gdb_flush_waypt_queue(QList<Waypoint*>* Q)
   while (!Q->isEmpty()) {
     const Waypoint* wpt = Q->takeFirst();
     if (wpt->extra_data) {
-      // FIXME
       // wpt->extra_data may be holding a pointer to a QString, courtesy
-      // the grossness at the end of write_waypt_cb().  If that leaks,
-      // (and I think it will) find some way to do the approximate equivalent
-      // of:
-      // delete static_cast<QString*>(wpt->extra_data);
+      // the grossness at the end of write_waypoint_cb().
+      delete static_cast<QString*>(wpt->extra_data);
     }
     delete wpt;
   }
@@ -256,12 +253,10 @@ GdbFormat::gdb_add_route_waypt(route_head* rte, Waypoint* ref, const int wpt_cla
                                 RAD(tmp->latitude), RAD(tmp->longitude)));
 
     if (fabs(dist) > 100) {
-      warning(MYNAME ": Route point mismatch!\n");
-      warning(MYNAME ": \"%s\" from waypoints differs to \"%s\"\n",
-              qPrintable(tmp->shortname), qPrintable(ref->shortname));
-      fatal(MYNAME ": from route table by more than %0.1f meters!\n",
-            dist);
-
+      fatal(MYNAME ": Route point mismatch!\n" \
+                   "  \"%s\" from waypoints differs to \"%s\"\n" \
+                   "  from route table by more than %0.1f meters!\n", \
+            qPrintable(tmp->shortname), qPrintable(ref->shortname), dist);
     }
   }
   Waypoint* res = nullptr;
@@ -1436,7 +1431,7 @@ GdbFormat::write_route(const route_head* rte, const QString& rte_name)
     garmin_fs_t* gmsd = garmin_fs_t::find(wpt);
 
     /* extra_data may contain a modified shortname */
-    FWRITE_CSTR((wpt->extra_data) ? (char*)wpt->extra_data : wpt->shortname);
+    FWRITE_CSTR((wpt->extra_data) ? *static_cast<QString*>(wpt->extra_data) : wpt->shortname);
 
     int wpt_class = wpt->wpt_flags.fmt_use;                    /* trick */
 
@@ -1655,6 +1650,7 @@ GdbFormat::write_waypoint_cb(const Waypoint* refpt)
     }
 
     name = mkshort(short_h, name);
+    wpt->extra_data = new QString(name);
     write_waypoint(wpt, name, gmsd, icon, display);
 
     finalize_item(fsave, 'W');
diff --git a/reference/route/gdbroutenametest.csv b/reference/route/gdbroutenametest.csv
new file mode 100644 (file)
index 0000000..929a7c3
--- /dev/null
@@ -0,0 +1,6 @@
+name,lat,lon
+RoutePoint,40.00,-105.00
+RoutePoint,40.01,-105.00
+RoutePoint,40.01,-105.01
+RoutePoint,40.02,-105.01
+
diff --git a/reference/route/gdbroutenametest~csv.csv b/reference/route/gdbroutenametest~csv.csv
new file mode 100644 (file)
index 0000000..76e8f89
--- /dev/null
@@ -0,0 +1,5 @@
+No,Latitude,Longitude,Name,Symbol\r
+1,40.000000,-105.000000,"RoutePoint","Waypoint"\r
+2,40.010000,-105.000000,"RoutePoint.1","Waypoint"\r
+3,40.010000,-105.010000,"RoutePoint.2","Waypoint"\r
+4,40.020000,-105.010000,"RoutePoint.3","Waypoint"\r
index dc8f003e516780bee4a3c87275a389b28754b1ad..390d0b9381ca3817e2856dbdaa9044c718f9d548 100644 (file)
@@ -29,3 +29,13 @@ compare ${REFERENCE}/gdb-sample.gpx ${TMPDIR}/gdb-sample_v3.gpx
 # don't choke if autoroute information is present.
 gpsbabel -i gdb,dropwpt -f ${REFERENCE}/gdb-sample-v3-autoroute.gdb -o gpx -F ${TMPDIR}/gdb-sample-v3-autoroute.gpx
 compare ${REFERENCE}/gdb-sample-v3-autoroute.gpx ${TMPDIR}/gdb-sample-v3-autoroute.gpx
+
+# test that the Route point Point names from the 'R' records match the Waypoint names from the 'W' records.
+# the names in the csv input are all identical which forces the gdb writer to uniquify them.
+gpsbabel -r  -i unicsv -f ${REFERENCE}/route/gdbroutenametest.csv -o gdb -F ${TMPDIR}/gdbroutenametest.gdb
+# if we don't match the names we will get a fatal error:
+# gdb: Route point mismatch!
+#   "RoutePoint" from waypoints differs to "RoutePoint"
+#   from route table by more than 1113.2 meters!
+gpsbabel -r -i gdb -f ${TMPDIR}/gdbroutenametest.gdb -o unicsv -F ${TMPDIR}/gdbroutenametest.csv
+compare ${REFERENCE}/route/gdbroutenametest~csv.csv ${TMPDIR}/gdbroutenametest.csv